class Grid < ActiveRecord::Base
  include ToHash 

  has_many :items

  validates_presence_of :name, :rows, :columns
  validates_numericality_of :rows, :columns
  validates_length_of :name, :maximum => 30

  def update_attributes(attributes)
    if attributes.has_key?(:items)
      attributes[:items] = attributes[:items].collect do |i|
        logger.debug("item attrs: #{i.to_s}")
        Item.new(i)
      end
    end
    super(attributes)
  end

end
